/**
 * @author 
 * @time 
 * @desc 
 * 注意各个TabPanel中的id都不要相同，若有相同则造成显示异常
 */
Ext.namespace("hrmsys.leave");


leaveInfoGridPanel = Ext.extend(Ext.grid.GridPanel,{
	id: 'leaveInfo',
	constructor: function(){
		Ext.QuickTips.init();
		leaveInfoStore = new Ext.data.JsonStore({
			url: 'leave-list.action',
			root: 'root',
 			totalProperty: 'totalProperty',
			fields: ['leaveAccount','leaveReason',
			         {name: 'leaveTime', mapping: 'leaveTime.time', dateFormat : 'time', type: 'date' },
			         'approveStatus','approveContent',
			         {name: 'approveTime', mapping: 'approveTime.time', dateFormat : 'time', type: 'date' },
			         'approveUser'
			]
		}); 
		var sm = new Ext.grid.CheckboxSelectionModel();
		var number = new Ext.grid.RowNumberer();
		leaveInfoGridPanel.superclass.constructor.call(this,{
			viewConfig: {
				forceFit: true
			},
			width: Ext.getCmp('mainTab').getActiveTab().getInnerWidth(),
			height: Ext.getCmp('mainTab').getActiveTab().getInnerHeight(),
			/**表格高度自适应 document.body.clientHeight浏览器页面高度 start**/
			monitorResize: true, 
			doLayout: function() {
				this.setWidth(document.body.clientWidth-205);
				this.setHeight(document.body.clientHeight-140);
				Ext.grid.GridPanel.prototype.doLayout.call(this); 
			} ,
			sm: sm,
			columns: [
				number,sm,
			{
				header: '学生号',
				dataIndex: 'leaveAccount',
				align: 'center'
			},{
				header: '请假原因',
				dataIndex: 'leaveReason',
				align: 'center'
			},{
				header: '请假日期',
				dataIndex: 'leaveTime',
				align: 'center',
				renderer: Ext.util.Format.dateRenderer('Y-m-d')
			},{
				header: '审核状态',
				dataIndex: 'approveStatus',
				align: 'center',
				renderer: function(value){
					if(value == -1) 	return "不通过";
					if(value == 0) 	return "审核中";
					if(value == 1) 	return "审核通过";
				}
			},{
				header: '审核内容',
				dataIndex: 'approveContent',
				align: 'center'
			},{
				header: '审核时间',
				dataIndex: 'leave.approveTime',
				align: 'center',
				renderer: function(value){
					if(Ext.util.Format.dateRenderer('Y-m-d') == '2000-01-01') return "";
					else Ext.util.Format.dateRenderer('Y-m-d');
				}
			},{
				header: '审核人',
				dataIndex: 'leave.approveUser',
				align: 'center',
			}],
			store: leaveInfoStore,
			//添加遮罩
			loadMask: {msg: '数据正在加载中,请稍后!'},
			
			tbar: new Ext.Toolbar({
			bodyStyle: 'padding-left: 5px;',
			//depart.js中定义了depart
			items: ['&nbsp;条目:',{
				xtype: 'combo',
				mode: 'local',//加载本地数据，必须加入
				store: new Ext.data.SimpleStore({
					fields: ['name','value'],
					data: [["","无"],['leaveAccount','学生号'],['leaveUser','姓名']]
				}),
				displayField: 'value',
				valueField: 'name',
				id: 'emp_condition',
				width: 50,
				autoLoad: true,
				listWidth: 50,
				editable: false,
				/*默认值 为query,当输入框有值时下拉列表将根据该值只显示过滤后的列表数据，可设置为all，不执行过滤*/
				triggerAction: 'all'
			},'&nbsp;内容:',{
				xtype: 'textfield',
				id: 'emp_conditionValue',
				width: 80,
//				listeners : {
//		                specialkey : function(field, e) {//添加回车事件
//		                    if (e.getKey() == Ext.EventObject.ENTER) {
//		                     // Ext.getCmp('empInfo').viewJob;
//		                    }
//		                }
//					}
			},{
				text: '&nbsp;&nbsp;查询',
				tooltip: '查询学生信息',
				iconCls: 'search',
				id: 'leave_query',
				handler: this.viewLeaveJob
			},{
				text: '删除',
				tooltip: '删除信息',
				iconCls: 'delete',
				id: 'leave_delete',
				hidden: 'true',
				handler: this.leaveDelFn
			},{
				text: '添加',
				iconCls: 'add',
				id: 'leave_add',
				hidden: 'true',
				tooltip: '添加信息',
				handler: this.leaveAddFn
			},{
				text: '审核',
				iconCls: 'update',
				id: 'leave_update',
				tooltip: '审核信息',
				hidden: 'true',
				handler: this.leaveApproveFn
			}]
		  }),
		  
		  	bbar: new PagingToolbar(leaveInfoStore, 20)
		});
		
		leaveInfoStore.load({
			params: {
				deptId: "",
				start: 0,
				limit: 20
			}
		}); 
	},
	viewLeaveJob: function(){
		leaveInfoStore.load({
			params: {
				start: 0,
				limit: 20
			}
		});
	},
	leaveDelFn: function(){
		var oSelMode = Ext.getCmp('leaveInfo').getSelectionModel();
		var oRecords = oSelMode.getSelections();
		var ids = "";
		for(var i=0;i<oRecords.length;i++){
			ids += oRecords[i].json['leaveId'];
			if(i != oRecords.length-1) ids += ",";
		};
		if(ids != null && ids != ""){
			Ext.Msg.confirm("提示","确定删除",function(button, text){
				if(button == "yes"){
					Ext.Ajax.request({
					url: 'leave-delete.action',
					success: function(response, options){
								var datas = Ext.util.JSON.decode(response.responseText);
								Ext.Msg.alert("提示", datas.msg, function(){
									Ext.getCmp('leaveInfo').getStore().reload();
								});
							},
					failure: function(response, options){
								Ext.Msg.alert("提示", '连接失败', function(){})
							},
					params: {
						ids: ids
					}
					});
				}
			});
		}else{
			Ext.Msg.alert("提示","请先选择",function(){});
		}
	},
	leaveAddFn: function(){
		var updateWin = new LeaveUpdateWin();
		updateWin.title = '请假信息添加';
		updateWin.show();
	},
	leaveApproveFn: function(){
		var updateWin = new LeaveApproveUpdateWin();
		updateWin.title = '请假信息审核';
		var selectionModel = Ext.getCmp('leaveInfo').getSelectionModel();
		var record = selectionModel.getSelections();
		if(record.length != 1){
			Ext.Msg.alert('提示','请选择一个');
			return;
		}
		Ext.getCmp('leaveApproveForm').getForm().load({
			method: 'post',
			url: 'leave-intoUpdate.action',
			params: {
				id: record[0].json['leaveId']
			},
			success: function(form, action){
				var obj = Ext.util.JSON.decode(action.response.responseText);
				Ext.getCmp("leaveApproveForm-id").setValue(obj[0].leaveId);
			}
		})

		updateWin.show();
	},
});

